/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBeans;

import facade.SuiLibFacade;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import valueObject.CourseVO;
import valueObject.ProfessorVO;
import valueObject.UniversityVO;
import valueObjetcsView.CourseVOvw;
import valueObjetcsView.ResultObject;

/**
 *
 * @author David
 */
@ManagedBean
public class searchMB {

    private String query;
    
    @EJB
    SuiLibFacade suilibFacade;
    /**
     * 
     * Creates a new instance of searchMB
     */
    public searchMB() {
    }

    /**
     * @return the category
     */
    
    
    public String getQuery() {
        return query;
    }

    /**
     * @param course the course to set
     */
    public void setQuery(String query) {
        this.query = query;
    }
    
    
    public void searchBar() {
        System.out.println("Buscando...."+query);
        List<ResultObject> findEverything = suilibFacade.findEverything(query);
        for(ResultObject res : findEverything) {
            System.out.println(res.getDescription());
            System.out.println(res.getId());
            System.out.println("------------------------");
        }
        
    }
    
    public ArrayList<CourseVOvw> getCourses() {
        ArrayList<CourseVOvw> courseVOvws = new ArrayList<CourseVOvw>();
        List<CourseVO> courseVOs = suilibFacade.getAllCoursesVO();
        for (CourseVO courseVO : courseVOs) {
            CourseVOvw vovw = new CourseVOvw();
            vovw.setId(courseVO.getId());
            vovw.setProfessorName(getProfessor(courseVO));
            vovw.setUniversityName(UniversityName(courseVO));
            vovw.setCourseName(courseVO.getName());
            vovw.setCategoryName(courseVO.getCategory().getName());
            courseVOvws.add(vovw);
        }
        return courseVOvws;
    }
    
    public String getProfessor(CourseVO courseVO) {
        //return ((ProfessorVO) courseVO.getProfessors().toArray()[0]).getName();
        return "Pruba profesor";
    }
    
    public String UniversityName(CourseVO courseVO) {
        //return ((ProfessorVO) courseVO.getProfessors().toArray()[0]).getUniversity().getName();
        return "Prueba universidad";
    }
    
    
//   public void setCourse(CourseVO course) {
//       this.courseVO = course;
//   }
}
